
package sg.edu.nus.iss.cats.dataaccess.mysql;

import sg.edu.nus.iss.cats.dataaccess.*;
import sg.edu.nus.iss.cats.model.*;

import java.util.*;


public class RoleManager {

    private static Hashtable roles = loadAllRoles ();
    private static Role[] roleArray;

    public Role[] findAllRoles () throws DAOException {
        return roleArray;
    }

    public Role findRole (String roleId) throws DAOException{
        Role r = (Role) roles.get (roleId);
        return r;
    }

    private static Hashtable loadAllRoles () {
        Hashtable newRoles = null;
        try {
            SQLObjectManager mgr = new SQLObjectManager (
            new RoleObjectHandler ());
            roleArray = (Role[]) mgr.getObjects ();
            newRoles = new Hashtable ();
            for (int i = 0; i < roleArray.length; i++) {
                Role r = (Role) roleArray[i];
                newRoles.put (r.getRoleId(), r);
            }
        } catch (Exception e) {
            newRoles = null;
        }
        return newRoles;
    }
}